package com.hzit.net;

import redis.clients.jedis.Jedis;

/**
 * Redis相关工具类
 */
public class RedisUtils {

    static  Jedis jedis = null;

    static {
        jedis = new Jedis("192.168.1.180",6379);
        jedis.auth("123456");
    }

    /**
     * 根据key获取内容
     * @return
     */
    public static String get(String key){
        return jedis.get(key);
    }

    /**
     * 根据 key/value设置
     * @param key
     * @param value
     */
    public static void set(String key,Object value){
        String set = jedis.set(key, value + "");
        System.out.println("set:"+set);
    }

    /**
     * key/value设置过期时间
     * @param key
     * @param value
     * @param expire
     */
    public static void set(String key,Object value,int expire){
        String set = jedis.set(key,value+"");
        Long expire1 = jedis.expire(key, expire);
    }

    /**
     * 设置key过期时间
     * @param key
     * @param expire
     */
    private static void setExpire(String key,int expire){
        Long expire1 = jedis.expire(key, expire);
    }

    //.....
    public static void main(String[] args) {
        set("weixin:token","xxxxyyyxx",7200);
    }



}
